package cn.edu.zjut.medlinebackend.controller;

import cn.edu.zjut.medlinebackend.mapper.UserMapper;
import cn.edu.zjut.medlinebackend.model.User;
import cn.edu.zjut.medlinebackend.utils.MyUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
public class HomeController {

    @Resource
    private UserMapper userMapper;
    @RequestMapping("/")
    public String inedx(HttpServletRequest request){
        String username = MyUtils.getCookieValue(request, "username");
        User byUsername = userMapper.getUserByUsername(username);
        if(byUsername == null || byUsername.getRole().equals("user")){
            return "user/home";
        }

        return "user/adminHome";
    }
}
